home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.12 Dec 94 / ThreadedSprocket / AppSpecific / App.cp next >
Encoding:
Text File  |  1994-10-17  |  3.9 KB  |  233 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        App.cp
  3.  
  4.     Contains:    Boilerplate application-specific code.
  5.                 
  6.     Written by: Dave Falkenburg
  7.  
  8.     Copyright:    © 1993-94 by Dave Falkenburg, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.      
  12.  */
  13.  
  14. #include <Windows.h>
  15. #include <Dialogs.h>
  16. #include <Menus.h>
  17. #include <Desk.h>
  18. #include <Errors.h>
  19. #include <Resources.h>
  20. #include <StandardFile.h>
  21. #include <Devices.h>        //    was <Desk.h>
  22.  
  23. #include "App.h"
  24. #include "FuturesDemo.h"
  25. #include "AppLib.h"
  26. #include "Window.h"
  27. #include "StandardMenus.h"
  28. #include "SplashWindow.h"
  29.  
  30. #include "ToolWindow.h"
  31. #include "DocWindow.h"
  32. #include "PreferencesDialogWindow.h"
  33. #include "MailableDocWindow.h"
  34.  
  35. #include "Preferences.h"
  36.  
  37. AppPreferences    gPreferences;
  38.  
  39. //    Function Prototypes:
  40.  
  41. void    AboutBox(void);
  42. void    OpenExistingDocument(void);
  43.  
  44.  
  45. OSErr
  46. SetupApplication(void)
  47.     {    
  48.     InsertMenu(GetMenu(mDebug),0);                //    Add Debug Menu
  49.  
  50.     if (gHasAOCE)
  51.         EnableItem(GetMHandle(mDebug),1);
  52.  
  53.     TToolWindow    * someTools = new TToolWindow(1025);
  54.  
  55.     gPreferences.fMailPreferences.fCreateMailerForNewDocuments = true;
  56.  
  57.     InitCursor();
  58.     InitFuturesDemo();
  59.     return (noErr);
  60.     }
  61.  
  62. void
  63. TearDownApplication(void)
  64.     {
  65.         CleanupFuturesDemo();
  66.     }
  67.     
  68. void
  69. HandleMenu(TWindow * topWindowObj, long menuCode)
  70.     {
  71.     short    menu = (short) (menuCode >> 16);
  72.     short    item = (short) (menuCode & 0xffff);
  73.     Str255    deskAccName;
  74.     
  75.     switch (menu)
  76.         {
  77.         case    mApple:
  78.             switch (item)
  79.                 {
  80.                 case    iAbout:
  81.                     AboutBox();
  82.                     break;
  83.                     
  84.                 default:
  85.                     GetItem(GetMHandle(mApple),item,deskAccName);
  86.                     (void) OpenDeskAcc(deskAccName);
  87.                     break;
  88.                 }
  89.             break;
  90.             
  91.         case    mFile:
  92.             switch (item)
  93.                 {
  94.                 case    iNew:
  95.                     OpenNewDocument();
  96.                     break;
  97.                 
  98.                 case    iOpen:
  99.                     OpenExistingDocument();
  100.                     break;
  101.                 
  102.                 case    iClose:
  103.                     HandleClose(FrontNonFloatingWindow());
  104.                     break;
  105.                     
  106.                 case    iPreferences:
  107.                     TPreferencesDialogWindow * prefsDialog = new TPreferencesDialogWindow;
  108.                     break;
  109.  
  110.                 case    iQuit:
  111.                     gDone = true;
  112.                     break;
  113.                     
  114.                 default:
  115.                     break;
  116.                 }
  117.             break;
  118.         
  119.         case    mEdit:
  120.             switch (item)
  121.                 {
  122.                 case    iShowOrHideClipboard:
  123.                     break;
  124.                     
  125.                 default:
  126.                     if ((!SystemEdit(item-1)) && (topWindowObj != nil))
  127.                         topWindowObj->DoEditMenu(item);
  128.                     break;
  129.                 }
  130.         
  131.         case    mDebug:
  132.             switch(item)
  133.                 {
  134.                 case    iNewMailableWindow:
  135.                     TMailableDocWindow *aWackyThing = new TMailableDocWindow;
  136.                     break;
  137.                 case    iPing:
  138.                     SendSimpleAEvt(kSillyEventClass, kPing1Event);
  139.                     break;
  140.                 case    iPing2:
  141.                     SendSimpleAEvt(kSillyEventClass, kPing2Event);
  142.                     break;
  143.                 default:
  144.                     break;
  145.                 }
  146.             break;
  147.             
  148.         default:
  149.             break;
  150.         }
  151.         
  152.     HiliteMenu(0);
  153.     }
  154.  
  155.  
  156. void
  157. AboutBox(void)
  158.     {
  159.     Handle            versionHandle;
  160.     StringPtr        nullStr = (StringPtr) "\p";
  161.     StringPtr        shortVersionString = nullStr;
  162.     short            itemHit;
  163.     
  164.     versionHandle = GetResource('vers',1);
  165.     if (versionHandle)
  166.         shortVersionString = (StringPtr) ((char *) *versionHandle + 6);
  167.     ParamText(shortVersionString,nullStr,nullStr,nullStr);
  168.     ReleaseResource(versionHandle);
  169.  
  170. #ifndef    powerc
  171.     itemHit = StandardAlert(kAboutBoxFor68K);
  172. #else
  173.     itemHit = StandardAlert(kAboutBoxForPowerPC);
  174. #endif
  175.  
  176.     if (itemHit == iCreditsButton)
  177.         StandardAlert(kCreditsBox);
  178.     }
  179.  
  180.  
  181. void
  182. OpenExistingDocument(void)
  183.     {
  184.     StandardFileReply    reply;
  185.     SFTypeList            ourTypes;
  186.     
  187.     Point    where = { -1, -1 };
  188.     
  189.     HiliteWindowsForModalDialog(false);
  190.     CustomGetFile((FileFilterYDUPP) nil, -1, ourTypes, &reply, 0, where,
  191.                   (DlgHookYDUPP) nil,StandardDialogFilterYD, nil,nil,nil);
  192.     HiliteWindowsForModalDialog(true);
  193.     }
  194.  
  195.  
  196. void
  197. ConvertClipboard(void)
  198.     {
  199.     }
  200.  
  201.  
  202. OSErr
  203. OpenNewDocument(void)
  204.     {
  205.     TDocWindow    *aNewWindow = new TDocWindow();
  206.     
  207.     if (aNewWindow)
  208.         return noErr;
  209.     else
  210.         return memFullErr;
  211.     }
  212.  
  213.  
  214. OSErr
  215. OpenDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  216.     {
  217.     return OpenNewDocument();    //    cheat for now…
  218.     }
  219.  
  220.  
  221. OSErr
  222. PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  223.     {
  224.     return noErr;
  225.     }
  226.  
  227.  
  228. Boolean
  229. QuitApplication(void)
  230.     {
  231.     return true;
  232.     }
  233.